<%--
  Created by IntelliJ IDEA.
  User: Edward_yang
  Date: 2017/12/14 0014
  Time: 9:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>商家列表</title>
    <script type="text/javascript">
        function formatterImg(value){
            if(value!=null){
                return '<img height="25px" src="'+value+'" alt="" />';
            }else{
                return '';
            }

        }
        //初始化分类数据 标签数据 城市数据
        $(function(){
            //分类
            $('#categoryId ').combotree({
                url : '${path }/category/allTree.do?root=1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto'
            });
            //城市
            $('#areaId').combotree({
                url : '${path }/areaInfo/allTree.do?root=1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto'
            });
            //标签
            $('#labelDetailCodeTree').combotree({
                url : '${path }/label/allTree.do?sellerId=-1&root=-1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto',
                onSelect: function(node) {
                    if (!$(this).tree('isLeaf', node.target)) {
                        alert("必须选择叶子节点");
                        //清除选中
                        $('#labelDetailCodeTree').combotree('clear');
                        return false;
                    }
                    $("#labelDetailCode").val(node.attributes);
                }
            });
        });
    </script>
<style>
    .color_001{
        color:#093;
    }
    .color_002{
        color: #f93;
    }
    .color_003{
        color: #f30;
    }

</style>
</head>
<script>
    var IsCheckFlag = true; //标示是否是勾选复选框选中行的，true - 是 , false - 否
    $(function(){
        $("#seller_tt").datagrid({//数据表格
            url:"${path}/seller/sellerList.do",
            width:"100%",
            height:"755px",
            fitColumns: true,//宽度自适应
            align:"center",
            loadMsg:"正在处理，请等待......",
            striped: true,//true是否把一行条文化
            idField:"id",//唯一性标示字段
            pagination:true,//显示分页栏
            rownumbers:true,//显示行号
            singleSelect:true,//true只可以选中一行
            pageSize:20,
            frozenColumns:[[//冻结字段
                {field:"ck",checkbox:true}
            ]],
            onClickCell: function (rowIndex, field, value) {
                       IsCheckFlag = false;
                     },
            onSelect: function (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                        IsCheckFlag = true;
                        $("#seller_tt").datagrid("unselectRow", rowIndex);
                    }
                },
            onUnselect: function (rowIndex, rowData) {
                  if (!IsCheckFlag) {
                          IsCheckFlag = true;
                         $("#seller_tt").datagrid("selectRow", rowIndex);
                      }
               },
            columns:[[//未冻结字段
                {field:"userZH",title:"商家账号",width:60},
                {field:"sellerName",title:"商家名称",width:60},
                {field:"sellerLogo",title:"商家logo",width:60,formatter:formatterImg},
                {field:"verifyType",title:"审核状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_002'>待审核</font>";
                        }else if(value=="1"){
                            return "<font class='color_001'>通过</font>";
                        }else if(value=="2"){
                            return "<font class='color_003'>拒绝</font>";
                        }
                    }
                },
                {field:"status",title:"状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_003'>禁用</font>";
                        }else if(value=="1") {
                            return "<font class='color_001'>正常</font>";
                        }
                    }
                },
                {field:"settlementRatio",title:"结算比例(%)",width:35},
                {field:"tel",title:"联系电话",width:60},
                {field:"address",title:"地址",width:80},
                {field:"productCount",title:"上架产品数量",width:35},
                {field:"initiatePrice",title:"起步产品价",width:30},
                {field:"virtaulCommentCount",title:"虚拟评论数量",width:35},
                {field:"virtualAppointmentCount",title:"虚拟预约数量",width:35},
                {field:"virtualCollectAccount",title:"虚拟收藏数量",width:35},
                {field:"commentCount",title:"评论数量",width:30},
                {field:"commentScore",title:"评分",width:20},
                {field:"appointmentCount",title:"预约数量",width:25},
                {field:"collectAccount",title:"收藏数量",width:25},
                {field:"ord",title:"排序",width:20},
                {field:"createDate",title:"创建时间",width:55,formatter: formatDatebox}
            ]],
            toolbar:[
            <shiro:hasPermission name="/seller/add.do">
                "-",
              {//工具条
                    text:"添加",
                    iconCls:"icon-add",
                    handler:function(){
                        var msg="添加";
                        $.modalDialog({
                            title : msg+'商家',
                            id:'modelAdd',
                            width : 1000,
                            height : 600,
                            href : '${path }/seller/gotoAddSeller.do'
                        });

                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/seller/edit.do">
              {//工具条
                    text:"修改",
                    iconCls:"icon-edit",
                     handler:function(){
                         var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                         if(rowsData.length<=0){
                             $.messager.alert('系统提示','请先选择要操作商家',"info");
                         }else{
                             var msg="修改";
                             $.modalDialog({
                                 title : msg+'商家',
                                 id:'modelEdit',
                                 width : 1000,
                                 height : 600,
                                 href : '${path }/seller/gotoEditSeller.do?sellerId='+rowsData[0].id
                             });
                         }

                  }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/seller/delete.do">
                {
                    text:"删除",
                    iconCls:"icon-remove",
                    handler:function(){
                        var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作商家',"info");

                        }else{
                            if(rowsData[0].status!=0){
                                var msg="正常状态"
                                $.messager.alert('系统提示','该商家属于'+msg,"info");
                                return;
                            }else{
                                deleteSeller(rowsData);
                            }


                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/seller/checkSeller.do">
                {//工具条
                    text:"审核",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作商家',"info");
                        }else{
                            $.modalDialog({
                                title : '审核商家',
                                id:'modelCheckSeller',
                                width : 300,
                                height :150,
                                href : '${path }/seller/gotoCheckSeller.do?sellerId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/selller/checkStauteSeller.do">
                {//工具条
                    text:"启用|禁用",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作商家',"info");
                        }else{
                            $.modalDialog({
                                title : '启用|禁用',
                                id:'modelCheckStauteSeller',
                                width : 300,
                                height : 150,
                                href : '${path }/seller/gotoCheckStauteSeller.do?sellerId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/selller/checkSellerAccountRatio.do">
                {//工具条
                    text:"修改结算比例",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作商家',"info");
                        }else{
                            $.modalDialog({
                                title : '修改结算比例',
                                id:'modelCheckSellerAccountRatio',
                                width : 300,
                                height : 150,
                                href : '${path }/seller/gotoCheckSellerAccountRatio.do?sellerId='+rowsData[0].id,
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/seller/editSellerServeLabel.do">
                {//工具条
                    text:"编辑服务标签",
                    iconCls:"icon-tip",
                    handler:function(){
                     var rowsData = $("#seller_tt").datagrid("getSelections");//找到所有选中的行
                     if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作商家',"info");
                        }else{
                            $.modalDialog({
                                title : '编辑服务标签',
                                id:'editServeLabel',
                                width : 400,
                                height : 400,
                                href : '${path }/seller/gotoEditSellerServeLabel.do?sellerId='+rowsData[0].id,
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                {text:"刷新",
                    iconCls:"icon-reload",
                    handler:function(){
                        $("#seller_tt").datagrid("clearSelections");//删除后取消所有选项
                        $("#seller_tt").datagrid("reload");
                    }
                },"-",
            ]
        });
        //扩展的Date的format方法(上述插件实现) 日期转换格式
        Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, // month
                "d+": this.getDate(), // day
                "h+": this.getHours(), // hour
                "m+": this.getMinutes(), // minute
                "s+": this.getSeconds(), // second
                "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
                "S": this.getMilliseconds()
                // millisecond
            }
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "")
                    .substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }
        //调用日期转化格式方法
        function formatDatebox(value) {

            if (value == null || value == '') {
                return '';
            }
            var dt;
            if (value instanceof Date) {
                dt = value;
            } else {
                dt = new Date(value);
            }

            return dt.format("yyyy-MM-dd hh:mm:ss");
        }

    });
    //删除
    function deleteSeller(rowsData) {
        $.messager.confirm("系统提示", "<p class='tipInfo'>你确定要删除吗?</p>",function(data){
            $.messager.progress();
            if(data){//判断是否删除
                if (rowsData){//判断是否找到当前行，找到后异步形式从数据库中删除当前记录
                    var sellerId=rowsData[0].id;
                    console.log(sellerId);
                    $.ajax({
                        type: "POST",
                        dataType: "JSON",
                        url: "${path}/seller/delete.do",
                        data: {"sellerId":sellerId},
                        success: function(data){
                            $.messager.progress("close");
                            if(data.success){
                                $.messager.show({
                                    title:"系统提示",
                                    msg:"删除成功!",
                                    timeout:600,
                                    style:"left:30%;top:10%",
                                    showType:"fade"
                                });
                                $("#seller_tt").datagrid("clearSelections");//删除后取消所有选项
                                $("#seller_tt").datagrid("reload");
                            }else{
                                $.messager.progress("close");
                                $.messager.alert("系统提示", data.msg,"error");
                            }
                        },
                        error:function(){
                            $.messager.progress("close");
                            $.messager.alert("系统提示", "服务器连接失败!","error");
                        }
                    });
                }
            }
        });
    }
    //刷新
    function reloadSellerDataGrid() {
        $('#seller_tt').datagrid('reload');
    }
    //关闭窗口
    function closeWin(str) {
        $('#'+str).dialog("close");
    }
    //重置
    function reset() {
        $("#sellerzh").val("");
        $("#sellerName").val("");
        $("#sellerVerifyType").val("-1");
        $("#sellerStatus").val("-1");
        $("#sellerCity").val("-1");
        $("#labelId").val("-1");
        window.location.href="${path}/seller/gotoSellerInfo.do";
        $("#seller_tt").datagrid('reload');
    }
    //查询
    function queryingSeller(){
        var queryParams = {
            phone:$("#sellerzh").val(),
            sellerName:$("#sellerName").val(),
            verifyType:$("#sellerVerifyType").val(),
            status:$("#sellerStatus").val(),
            cityid:$("#areaId").combotree("getValue"),
            classifyid:$("#categoryId").combotree("getValue"),
            labelCode:$("#labelDetailCode").val(),
        };
        var options = $("#seller_tt").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#seller_tt").datagrid('options').url = "${path}/seller/sellerList.do";
        $("#seller_tt").datagrid('options').queryParams = queryParams;
        $("#seller_tt").datagrid('reload');
    }

</script>
<body style="padding:0px" >
<h2 style="margin-bottom: 0px">商家列表</h2>
<div style="border:3px solid rgb(95,158,160)">
</div>

<div class="main" style="width: 100%; margin: 20px auto ">
    <style type="text/css">
        .searchTab{font:12px arial,helvetica,sans-serif;border:2px solid rgb(95,158,160)}
        .searchTab td{font:100% arial,helvetica,sans-serif;height:30px;padding:5px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
        .searchTab{width:100%;border-collapse:collapse}
        .searchTab td{border:0px solid #e0e0e0;padding-left:5px;text-align: right}
    </style>
    <table class="searchTab">
        <tr>
            <td class="search_toright_td"  style="width:60px;">商家账号：</td>
            <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="sellerzh" name="phone" class="searchTabinput"/></td>
            <td class="search_toright_td" style="width:60px;">商家名称：</td>
            <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="sellerName" name="sellerName" class="searchTabinput"/></td>
            <td class="search_toright_td" style="width:60px;">审核状态：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="sellerVerifyType" style="width:80px;" class="querySelect">
                    <option value="-1">--请选择--</option>
                    <option value="0">待审核</option>
                    <option value="1">通过</option>
                    <option value="2">拒绝</option>
                </select>
            <td class="search_toright_td" style="width:60px;">状态：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="sellerStatus" style="width:80px;" class="querySelect">
                    <option value="-1">--请选择--</option>
                    <option value="0">禁用</option>
                    <option value="1">正常</option>
                </select>
            </td>
            <td class="search_toright_td" style="width:60px;">城市：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="areaId" name="areaId" style="width:150px;"></select>
            </td>
            <td class="search_toright_td" style="width:60px;">分类：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="categoryId" name="categoryId" style="width:150px;"></select>
            </td>
            <td class="search_toright_td" style="width:60px;">标签：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="labelDetailCodeTree" name="labelDetailCodeTree" style="width:150px;"></select>
                <input id="labelDetailCode" name="labelDetailCode" type="hidden">
            </td>

            <td class="search_toleft_td">&nbsp;&nbsp;
                <a id="btnCancel" class="easyui-linkbutton" icon="icon-search" href="javascript:queryingSeller()">查询</a>
                <a id="btnCance2" class="easyui-linkbutton"  iconCls="icon-undo" href="javascript:reset()">重置</a>
            </td>
        </tr>
    </table>
    <table id="seller_tt" style="border: 1px solid rgb(95,158,160);white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
    </table>

</div>
</body>
</html>
